package com.example.controller;

import com.example.config.ResponseVO;
import com.example.pojo.LeaveRequest;
import com.example.pojo.dto.LeaveRequestDTO;
import com.example.service.LeaveRequestService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/leave")
public class LeaveRequestController {
    @Resource
    private LeaveRequestService teacherLeavesService;

    // 通过班级查询出未批准的请假信息
    @PostMapping("/leaveRequestListByClassId/{classId}")
    public ResponseEntity<ResponseVO<List<LeaveRequest>>> leaveRequestListByClassId(@PathVariable Long classId) {
        return teacherLeavesService.leaveRequestListByClassId(classId);
    }

    // 根据学生id查询该学生是否还有未批准的假期
    @PostMapping("/leaveRequestByStuId/{stuId}")
    public ResponseEntity<ResponseVO<LeaveRequest>> leaveRequestByStuId(@PathVariable Long stuId){
        return teacherLeavesService.leaveRequestByStuId(stuId);
    }

    // 添加学生请假信息
    @PostMapping("/addLeaveRequest")
    public ResponseEntity<ResponseVO<LeaveRequest>> addLeaveRequest(@RequestBody LeaveRequestDTO leaveRequestDTO) {
        return teacherLeavesService.addLeaveRequest(leaveRequestDTO);
    }

    // 查询未处理的请假批准
    @PostMapping("/getNotProcessedLeave/{classId}")
    public ResponseEntity<ResponseVO<List<LeaveRequestDTO>>> getNotProcessedLeave(@PathVariable Long classId) {
        return teacherLeavesService.getNotProcessedLeave(classId);
    }

    // 查询已处理的请假批准
    @PostMapping("/getProcessedLeave/{classId}")
    public ResponseEntity<ResponseVO<List<LeaveRequestDTO>>> getProcessedLeave(@PathVariable Long classId) {
        return teacherLeavesService.getProcessedLeave(classId);
    }

    // 批准假期
    @PostMapping("/processedLeave/{remark}/{teacherId}")
    public ResponseEntity<ResponseVO<String>> processedLeave(@PathVariable String remark,@PathVariable Long teacherId,@RequestBody LeaveRequestDTO leaveRequestDTO) {
        return teacherLeavesService.processedLeave(remark, teacherId, leaveRequestDTO);
    }
}
